package com.nuance.assignment.fileInfo.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.GWT.UncaughtExceptionHandler;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.Window;
import com.nuance.assignment.fileInfo.client.presenter.FileInfoPresenter;
import com.nuance.assignment.fileInfo.client.util.FileInfoConstants;
import com.nuance.assignment.fileInfo.client.util.FileInfoMessages;
import com.nuance.assignment.fileInfo.client.view.FileInfoView;

/**
 * Entry point into the application
 * 
 * @author parag
 *
 */
public class FileInfoEntryPoint implements EntryPoint {

	private final FileInfoMessages fileInfoMessages = GWT.create(FileInfoMessages.class);
	private final FileInfoConstants fileInfoConstants = GWT.create(FileInfoConstants.class);
	private final DateTimeFormat dateTimeFormat = DateTimeFormat.getFormat(fileInfoMessages.dateFormat());
	
	private final FileInfoView fileInfoView = new FileInfoView(fileInfoMessages, fileInfoConstants, dateTimeFormat);
	private final FileInfoPresenter fileInfoPresenter = new FileInfoPresenter(fileInfoConstants);
	/**
	 * The uncaught exception handler to show any exception occurring in browser.
	 */
	private final UncaughtExceptionHandler uncaughtExceptionHandler = new UncaughtExceptionHandler(){
		@Override
		public void onUncaughtException(Throwable e) {
			Window.alert(e.getMessage());
		}
	};

	@Override
	public void onModuleLoad() {
		GWT.setUncaughtExceptionHandler(uncaughtExceptionHandler);
		fileInfoPresenter.present(fileInfoView);
	}

}
